package com.example.zluserservice.service.impl;

import com.example.zluserservice.dto.UserAuth;
import com.example.zluserservice.dto.response.UserResDTO;
import com.example.zluserservice.service.IUserService;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author zhenliu（孙凌岳）
 * @Description 实现UserDetailsService
 * DaoAuthenticationProvider调用你项目中的UserDetailsService的loadUserByUsername方法加载用户
 * @Date 2025/6/15 17:27
 * @Version 1.0
 */
@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    @Resource
    private IUserService userService;

    /**
     * 自己实现加载方法
     * @param username
     * @return
     * @throws UsernameNotFoundException
     */
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        UserResDTO userResDTO = userService.findUserResDTOForLogin(username);
        return new UserAuth(userResDTO);
    }
}
